package com.assistant.util;

import org.springframework.stereotype.Service;

import java.net.URI;
import java.util.HashMap;
import java.util.Map;

/**
 * HttpUtils
 *
 * @author yingjianhua
 */
@Service
public class HttpUtil {

    public Map<String, String> resolveQuery(URI uri) {
        String querySplit = "&";
        Map<String, String> map = new HashMap<>(16);
        for (String s : uri.getQuery().split(querySplit)) {
            int i = s.indexOf("=");
            String key = i != -1 ? s.substring(0, i) : s;
            String value = null;
            if (i != -1) {
                value = i == s.length() - 1 ? "" : s.substring(i + 1);
            }
            map.put(key, value);
        }
        return map;
    }
}
